package cn.plushine.controller;

import cn.plushine.utils.GaoDeUtils;
import cn.plushine.utils.ResMapUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 调用高德API，返回省市区数据
 */
@Api(tags = "省市区数据")
@RestController
@RequestMapping("/admin/product")
public class DistrictController {

    // 根据关键字响应下一级地区信息
    @ApiOperation(value = "根据关键字响应下一级地区信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String")
    })
    @GetMapping("/district")
    public HashMap<String, Object> district(String keywords) {
        try {
            // 调用工具类获取返回数据
            String district = GaoDeUtils.district(keywords);
            // 成功响应
            return ResMapUtils.encapsulation(200, "获取省市区（县）信息成功！", district);
        } catch (Exception e) {
            // 添加失败
            return ResMapUtils.encapsulation(201, "获取省市区（县）信息失败！", null);
        }
    }
}
